# 探究植物生长受光照、水分和温度三种因素的影响情况，光照、水分、温度都分为低和高两种水平
# 植物的生长情况由植物生长高度和叶子数量来度量
import multiprocessing
import random
from pprint import pprint

init_state = {
    'height': 0,
    'leaf_num': 0
}
params = {
    'sunlight': [1, 2, 3, 4, 5],
    'water': ['low', 'mid', 'high'],
    'temperature': [1, 10],
}


def dfs(x, k, space, values, index, capacity):
    if x == k:
        s = 0
        for key in capacity.keys():
            capacity[key].append(index[s])
            s = s + 1
        return capacity

    i = 0
    while i < len(values[x]):
        index[x] = values[x][i]
        capacity = dfs(x + 1, k, space, values, index, capacity)
        i = i + space

    return capacity


# space为间隔数，表示每间隔space个水平进行取样
# param为字典，表示因子水平的上限和下限/表示因子的不同水平。即对于param中每一项的数组：要么包含两项表示下限和上限要么包含n项表示该因子的不同水平。
# 例如param = {'x':[1,2,3,4,5]};
# space=0, 取到的结果为{'x': [1,2,3,4,5]};
# space=1, 取到的结果为{'x': [1,3,5]};
def getCapacity(param, space):
    assert space >= 0 or type(space) != int, '间隔space必须为正整数'
    capacity = {}
    for item in param.items():
        assert type(item[1]) == list, '参数中的因子水平必须为数组的形式'
        capacity.update(dict([(item[0], [])]))

    index = []
    for i in range(len(capacity)):
        index.append(0)
    capacity = dfs(0, len(capacity), space+1, list(param.values()), index, capacity)

    return capacity


def run():
    capacity = getCapacity(param=params, space=1)
    pprint(capacity)


if __name__ == "__main__":
    multiprocessing.freeze_support()
    run()
